import os
import textwrap
import time

import google.generativeai as genai
import PIL.Image

from IPython.display import Markdown

genai.configure(api_key = 'AIzaSyCYKdkqTOdlmjdauzFVDoFz_rEYwsazTH0')

def to_markdown(text):
  text = text.replace('•', '  *')
  return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))

model = genai.GenerativeModel('gemini-pro-vision')

files = os.listdir("/Users/yuwang/Desktop/Gemini in Political Science/data/images")

def image_analysis(image_name):
    print("Image name", image_name)
    img = PIL.Image.open("./../data/images/" + image_name)
    start = time.time()
    prompt = 'Use up to four words to describe the sentiment undertone of the image.'
    try:
    	response = model.generate_content([prompt, img])
    	print(response.text.strip())
    except:
        print("failed at", image_name)
    #print("====" * 10)


x = """abc-news_0003_2.jpg
vice-news_0000_1.jpeg
al-jazeera-english_0004_4.jpg
business-insider_0019_4.jpeg
abc-news_0005_4.jpg"""
for i in x.split("\n"):
	image_analysis(i.strip())
